package com.webflux.dmeo.functionCompileDemo;

import java.text.DecimalFormat;
import java.util.function.Function;

/**
 * Created by wangzhanjin on 2018/5/30.
 */

interface IMoneyFormat {
    //只是代表输入是int类型，输出是String
    String format(int i);
}

class MyMoney{
    private final int money;
    public MyMoney(int money) {
        this.money = money;
    }
    public void printMoney(Function<Integer,String> moneyFormat) {
        System.out.println("我的存款："+moneyFormat.apply(this.money));
    }
}

public class MoneyDemo {
    public static void main(String[] args) {
        MyMoney myMoney = new MyMoney(99900);
        myMoney.printMoney(i->new DecimalFormat("#,###").format(i));
        //或者接口定义拉出来
        Function<Integer,String> moneyFormat = i -> new DecimalFormat("#,###").format(i);
        //函数接口链式操作
        myMoney.printMoney(moneyFormat.andThen(s->"人民币"+s));
    }
}
